#delimit;
version 12.1;
set more off;
program drop _all;
  quietly log;
  local logon = r(status);
  if "`logon'" == "on" {; log close; };
log using bos2015prq.log, text replace;


/* *************************************************************      */
/*  File Name:  bos2016prq.do                                         */
/*  Authors:    Frederick J. Boehmke and Emily Schilling              */
/*  Date:       May 02, 2018                                          */
/*  Purpose:    Replication of pivotal politics and initiative use    */
/*              models for Boehmke, Osborn, and Schilling, SPPQ,      */
/*		2015. This runs the models in Tables 2 and 3 and      */
/*              generates Figure 2.                                   */
/*  Input:      bos2015prq.dta                                        */
/*              bos2015prq-CA.dta                                     */
/*  Output:     bos2015prq.log,                                       */
/*              bos2015prq-table2.txt                                 */
/*              bos2015prq-table3.txt                                 */
/*              bos2015prq-fig2.gph                                   */
/*  Programs:   estout.ado                                            */
/* *************************************************************      */


use bos2015prq, clear;


	/**************************************************************/
	/* Analyze Osborn, Wright, et. al. data with |F-V| and |V-O|. */
	/**************************************************************/

	
nbreg init_use2_iri gridint_wr statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if (sample01==1 & mod(year,2)==0), robust;
	
  estimates store sample01_grid;
	
nbreg init_use2_iri gridint_wr statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if (sample02==1 & mod(year,2)==0), robust;

  estimates store sample02_grid;
  
nbreg init_use2_iri filibint_wr vetoint_wr statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if (sample01==1 & mod(year,2)==0), robust;
	
  estimates store sample01_fv;
	
nbreg init_use2_iri filibint_wr vetoint_wr statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if (sample02==1 & mod(year,2)==0), robust;

  estimates store sample02_fv;
   
	
	/**************************************************************************/
	/* Analyze Shor and McCarty data, testing w/ |F-L| & |V-L| (small sample).*/
	/* This is just for comparison, not included in Table 2.                  */ 	
	/**************************************************************************/
	 
  
nbreg init_use2_iri filibint_sm vetoint_sm statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if (sample02==1 & mod(year,2)==0), robust;
	
  estimates store sample02_smm;
  
  
	/***************************************************************************/
	/* Analyze Shor and McCarty data, testing with |F-L| & |V-L| (full sample).*/						
	/***************************************************************************/
  
  
nbreg init_use2_iri gridint_sm statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if mod(year,2)==0, robust;
	
  estimates store fullsample_smm_grid; 

nbreg init_use2_iri filibint_sm vetoint_sm statinit consinit init_dist init_sigs init_circ init_circ_unl 
	unif_any totpop rpcpinc citi6010 if mod(year,2)==0, robust;
	
  estimates store fullsample_smm; 

	
	/*****************/
	/* Make Table 2. */
	/*****************/
		
		
estout sample01_fv sample01_grid sample02_fv sample02_grid fullsample_smm fullsample_smm_grid using bos2015prq-table2.txt, replace style(tab)  
	cells(b(star fmt(3)) se(fmt(3) par)) starlevels(* 0.10 ** 0.05) 
	stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) 
	varlabels(_cons constant)  
	order(filibint* vetoint* gridint*)
	mlabels("Clark et al." "" "Clark et al. extended" "" "Shor & McCarty" "")
	collabels(none)
	label varwidth(40) modelwidth(6);
	
	
	/****************************/
	/* Analyze California data. */
	/****************************/
		
use bos2015prq-CA, clear;

		/* Create time trend variables. */

  summarize year;

  generat time = year - r(min);
  generat time_sq = time^2;
  generat time_cube = time^3;

  mkspline _spline = time if year>=1912 & year <= 2010, cubic nknots(5) displayknots;

		/* Run the models. */

nbreg init_use2_iri filibint_ca vetoint_ca _spline*, robust;

	estimates store CA01;

nbreg init_use2_iri gridint_ca _spline*, robust;

	estimates store CA01_grid;

		/* Now with subset of observations with independent variables. */
	
nbreg init_use2_iri filibint_ca vetoint_ca citi6010 totpop rpcpinc unif_any time time_sq, robust;

	estimates store CA02;

nbreg init_use2_iri gridint_ca citi6010 totpop rpcpinc unif_any time time_sq, robust;

	estimates store CA02_grid;

	
	/*****************/
	/* Make Table 3. */
	/*****************/
		
		
estout CA01 CA01_grid CA02 CA02_grid using bos2015prq-table3.txt, replace style(tab)  
	cells(b(star fmt(3)) se(fmt(3) par)) starlevels(* 0.10 ** 0.05) 
	stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) 
	varlabels(_cons constant)  
	order(filibint* vetoint* gridint*)
	mlabels("1911-2003" "" "1961-2003" "")
	collabels(none)
	label varwidth(40) modelwidth(6);
	
	
	/******************/
	/* Make Figure 2. */
	/******************/
		
		
twoway lowess init_use2_iri year if year>=1911, scheme(s1color) bwidth(0.15)
	lcolor(red) mcolor(red) msize(small)
	ylabel(#5, grid)
	ytitle(Number of Initiatives, axis(1) size(large))
  || 	lowess filibint_ca year if mod(year,2)==1, yaxis(2) bwidth(0.15)
	lcolor(blue) mcolor(blue) msize(small)
  || 	lowess vetoint_ca year if mod(year,2)==1, yaxis(2) bwidth(0.15)
	lcolor(green) mcolor(blue) msize(small)
	ylabel(0(0.25)1, axis(2))
	ytitle(|F-L| & |O-L| Interval, axis(2) size(large))
	xsize(5) ysize(3)
	legend(label(1 Initiative Use) label(2 Filibuster Interval) label(3 Veto Override Interval) rows(1))
	saving(bos2015prq-fig2, replace);

	
	/*********************************************************************/
	/* Robustness analysis of CA results to the specific time variables. */
	/*********************************************************************/
	

nbreg init_use2_iri filibint_ca vetoint_ca, robust;
	
nbreg init_use2_iri filibint_ca vetoint_ca time, robust;
	
nbreg init_use2_iri filibint_ca vetoint_ca time time_sq, robust;

nbreg init_use2_iri filibint_ca vetoint_ca time time_sq time_cube, robust;
	
	
	/**********************************************************************/
	/* Analyze California data, with no supermajority gridlock post 1978. */
	/**********************************************************************/

	
nbreg init_use2_iri gridint_ca alt2gridlockCA _spline*, robust;
	
nbreg init_use2_iri gridint_ca alt2gridlockCA citi6010 totpop rpcpinc unif_any time time_sq, robust;
	
	
log close;
clear;
exit, STATA;
